package com.syt.cellphone.information.data.dao

import androidx.lifecycle.LiveData
import androidx.room.*
import com.syt.cellphone.information.data.pojo.PhoneBase

/**
 *  @author: syt
 *  创建时间: 2020/8/3 15:46
 *  @功能   基础数据dao
 */
@Dao
interface PhoneBaseDao {

    /**
     * 全部数据列表 liveData
     */
    @Query("select * from phone_base order by baseId asc")
    fun observeAll(): LiveData<List<PhoneBase>>

    /**
     * 全部数据列表
     */
    @get:Query("select * from phone_base order by baseId asc")
    val all: List<PhoneBase>

    /**
     * 根据id 查询
     */
    @Query("select * from phone_base where baseId = :baseId")
    fun get(baseId: Int): PhoneBase

    @Query("select * from phone_base order by baseId asc")
    fun all(): List<PhoneBase>

    @Query("delete from phone_base")
    fun deleteData()

    /**
     * 插入数据
     * OnConflictStrategy.REPLACE：取代旧数据同时继续事务。
     */
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insert(vararg phoneBase: PhoneBase)

    @Update
    fun update(vararg phoneBase: PhoneBase)

    @Delete
    fun delete(vararg phoneBase: PhoneBase)
}